function [Sample] = Sampling_BoxConstraint(n, Region, ObjFunc)
% the sampling method for box constrainted problems
%   d: problem dimension
%   n: number of samples
%   Region: 1 -by- 2d vector or n -by- 2d matrix, [d1_start, d1_end, d2_start, d2_end, ...]
%   Sample: n -by- (1+d) matrix, [objective value, x1, x2, ...]

d = size(Region,2)/2; % the problem dimension
if size(Region,1) == 1
    Region = repmat(Region,[n,1]);
end
x_id = (1:d).*2-1; % the start position of each dimension
Sample = zeros(n,1+d);
SampleValue = rand([n,d]);
Sample(:,2:(d+1)) = SampleValue.*(Region(:,x_id+1)-Region(:,x_id)) + Region(:,x_id);
Sample(:,1) = ObjFunc(Sample(:,2:(d+1)));
end